#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    : sheet.py
@Author  : different && 道阻且长,行则将至 行而不辍,未来可期
@Time    : 2021/9/15 17:58
@Desc    : 主属性视图

"""

from flask import render_template, request

from apps.view import sheet_bp
from expand import login_required
from expand.exp_data.exp_sheet_data import SheetData


@sheet_bp.route('/sheet/<pk>')
@login_required
def sheet(pk):
    if request.method == 'GET':
        sheet_cls = SheetData(pk)
        sheet_data = sheet_cls.sheet_data()
        sheet_title = sheet_cls.text_title()
        cols = sheet_cls.cols
        attr = sheet_data.pop()
        for i, v in enumerate(attr):
            cols.insert(i + 1, {"field": v, "title": v, "align": "center", "width": 100,
                                "style": "background-color:#BFDBAE"})
        return render_template('sheet.html', data=sheet_data, cols=cols, sheet_title=sheet_title)
